<template>
  <div class="container">
    <div class="app-container">
      <el-tree default-expand-all :data="depts"  :props="defaultProps" :expand-on-click-node="false">
       <template v-slot="{data}">
         <el-row style="width: 100%; height:40px;" type="flex" justify="space-between">
            <el-col :span="18">{{ data.name }}</el-col>
            <el-col :span="6">
                  <span class="tree-manager">{{ data.managerName }}</span>
                  <el-dropdown @command="handleCommand">
                  <!-- 显示区域内容 -->
                  <span class="el-dropdown-link">
                  操作<i class="el-icon-arrow-down el-icon--right"></i>
                  </span>
                  <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item command="add">添加子部门</el-dropdown-item>
                  <el-dropdown-item command="edit">编辑部门</el-dropdown-item>
                  <el-dropdown-item command="delete">删除</el-dropdown-item>
                  </el-dropdown-menu>
               </el-dropdown>
            </el-col>
        </el-row>
       </template>
      </el-tree>
    </div>
    <!-- 放置弹层组件 -->
    <addDept :showDialog.sync="showDialog"></addDept>
  </div>
</template>
<script>
import { getDepartment } from "@/api/department"
import { transListToTreeData } from "@/utils/index"
import addDept from "./components/add.dept.vue"
export default {
      name:'Department',
      data() {
        return {
                  showDialog: false,
                  depts: [{
                    name: '老许教育',
                    managerName:'管理员',
                  children: [{
                  name: '总裁办',
                  }, {
                  name: '行政部'
                  }, {
                  name: '人事部'
                  }]
                  }],
                  defaultProps: {
                  children: 'children',
                  name: 'label'
                  }
              }  
  },
  components: {
    addDept
  },
  created() {
    this.getDepartment()
  },
  methods: {
    //封装好方法，获取数据
        async getDepartment(){
          const res = await getDepartment()
          this.depts = transListToTreeData(res, 0)
    },
    // 下拉菜单点击事件
    handleCommand(value) {
      if (value === 'add') {
        this.showDialog = true
      } else if (value === 'edit') {
        
      }
       
        }
      }
}
</script>
<style scoped>
.app-container{
      padding: 30px 130px;
      font-size:14px;
}
.tree-manager{
width: 80px;
display: inline-block;
margin: 10px;
}
</style>
